$(document).ready(function(){


	//photoGridAjaxEvent('#photos', "displayAlbumsList/"+idPhotographer+"/20/1/", myProfile);
	
	if (idAlbum == 0){
		photoGridAjaxEvent('#photos_album', "/displayAlbumsList/"+idPhotographer+"/10/1/", myProfile);
	}
	else {
		photoGridAjaxEvent('#photos_album', "/displayAlbumPhoto/"+idPhotographer+"/" + idAlbum +"/10/1/", myProfile);		
	}
	photoGridAjaxEvent('#photos_followed', 'displayFollowedList/'+idPhotographer);
	photoGridAjaxEvent('#photos_fav', 'displayFavorites/'+idPhotographer+'/10/1');
	initMap('profile', zoomed, zoomLevel, zoomLat, zoomLong, idAlbum);
	
	$('.gridElementAlbum').live('mouseenter', function() {
		$(this).children('.gridInfoAlbum').children('.whiteBorderAlbum').animate({opacity: 1 }, 200, function() {});
		$(this).children('.gridInfoAlbum').children('.infoBoxAlbum').animate({opacity: 1 }, 200, function() {});
	});
	
	$('.gridElementAlbum').live('mouseleave', function() {
		$(this).children('.gridInfoAlbum').children('.whiteBorderAlbum').animate({opacity: 0 }, 200, function() {});
		$(this).children('.gridInfoAlbum').children('.infoBoxAlbum').animate({opacity: 0.7 }, 200, function() {});
	});

	$('.gridElementAlbum').live('click', function() {
		var idAlbum = $(this).attr("id").substring(5);
		photoGridAjaxEvent('#photos_album', "displayAlbumPhoto/"+idPhotographer+"/"+idAlbum+"/10/1/");
		$.ajax({
		   url: "getPhotoCoordsByAlbum/"+idAlbum+"/",
		   success : function(data){
				$('#photos_album').attr('type', "displayAlbumPhoto/"+idPhotographer+"/"+idAlbum);
				readPhotoData(data, true);
				$.ajax({
				   url: "/getZoomInfo/"+idAlbum+"/",
				   success : function(data){
						readZoomData(data, true);
						
				   }
				});	
		   }
		});	
	});
	
	$('#retourAlbum').live('click', function() {
		var url = $(this).attr("src");
		photoGridAjaxEvent('#photos_album', url);
		$.ajax({
		   url: "getPhotoCoords/111111/",
		   success : function(data){
				$('#photos_album').attr('type', "displayAlbumsList/"+idPhotographer);
				readPhotoData(data, true);
				$.ajax({
				   url: "/getZoomInfo/0/",
				   success : function(data){
						readZoomData(data, true);
						
				   }
				});
		   }
		});
	});
});

function readZoomData(data){
	var nodes   = data.getElementsByTagName("zoom");
	
	for (var i=0, c=nodes.length; i<c; i++) {
		if (nodes[i].getAttribute("zoomed") == 1){
			flashMovie.setZoomLongLat(nodes[i].getAttribute("zoomLevel"), nodes[i].getAttribute("zoomLat")/100000000, nodes[i].getAttribute("zoomLong")/100000000);
		}
		else {
			flashMovie.setZoomLongLat(100, 0, 40);
		}
	}
}
